var Crawler=require("crawler");
var downloadContent=require("./download");
var c=new Crawler({
    maxConnections:10,
    retries:5,
    callback:function(error,res,done){
        if(error){
            console.log(error);
        }else{
            var $ = res.$;
            // $ is Cheerio by default
            //a lean implementation of core jQuery designed specifically for the server
            console.log($("title").text());
        }
        done();
    }
})

c.queue([{
    uri:'http://www.94aw.com/type/4.html',
    jQuery: true,

    // The global callback won't be called
    callback: function (error, res, done) {
        if(error){
            console.log(error);
        }else{
            var total_page=68;
            var $=res.$;
            for(var i=1;i<=total_page;i++){
                downloadContent(i,c)
            }
        //    $(".container:last-child").each(function(index,item){
        //        if($(item).text()==="尾页"){
        //         total_pag = $(item).attr('href');
        //         var regexp = /[0-9]+/g;
        //         total_page = total_pag.match(regexp)[0]; // 总页数
        //         for(var i=1;i<=total_page;i++){
        //             // downloadContent(i,c)
        //         }

        //         // console.log(total_page)
        //        }
        //    })
        }
        done();
    }
}])

